﻿using System;
using System.Web;
using System.Globalization;

namespace SystemX.Web
{
	public static partial class Utils
	{

		/// <summary>
		/// Translates the specified string using the resource files.
		/// </summary>
		public static string Translate(string text)
		{
			return Translate(text, null, null);
		}

		/// <summary>
		/// Translates the specified string using the resource files.  If a translation
		/// is not found, defaultValue will be returned.
		/// </summary>
		public static string Translate(string text, string defaultValue)
		{
			return Translate(text, defaultValue, null);
		}

		/// <summary>
		/// Translates the specified string using the resource files and specified culture.
		/// If a translation is not found, defaultValue will be returned.
		/// </summary>
		public static string Translate(string text, string defaultValue, CultureInfo culture)
		{
			object resource=default(object);

			if (culture == null)
				resource = HttpContext.GetGlobalResourceObject("labels", text);
			else
				resource = HttpContext.GetGlobalResourceObject("labels", text, culture);

			if (resource != null)
				return resource.ToString();

			if (string.IsNullOrEmpty(defaultValue))
				return string.Format("Missing Resource [{0}]", text);
			else
				return defaultValue;
		}

	}
}
